Current Location: Home> Function Categories> filter_input

filter_input

Get a specific external variable by name and can be processed by filter
Name:filter_input
Category:Filter
Programming Language:php
One-line Description:Get input from outside the script and filter it.

Definition and usage

filter_input() function gets input from outside the script and filters it.

This function is used to verify variables from non-secure sources, such as user input.

This function can obtain input from various sources:

  • INPUT_GET
  • INPUT_POST
  • INPUT_COOKIE
  • INPUT_ENV
  • INPUT_SERVER
  • INPUT_SESSION (Not yet implemented)
  • INPUT_REQUEST (Not yet implemented)

If successful, the filtered data is returned, if failed, false, if variable parameter is not set, NULL.

Example

In this example, we use filter_input() function to filter a POST variable. The accepted POST variable is a legal e-mail address.

 <?php
if ( ! filter_input ( INPUT_POST , 'email' , FILTER_VALIDATE_EMAIL ) )
 {
 echo "E-Mail is not valid" ;
 }
else
 {
 echo "E-Mail is valid" ;
 }
?>

The output is similar:

 E-Mail is valid

grammar

 filter_input ( input_type , variable , filter , options )
parameter describe
input_type Required. Specify the input type. See the possible types in the list above.
variable Specify the variables to be filtered.
filter

Optional. Specifies the ID of the filter to be used. The default is FILTER_SANITIZE_STRING.

See the complete PHP Filter Function Reference Manual for possible filters.

The filter ID can be an ID name (such as FILTER_VALIDATE_EMAIL), or an ID number (such as 274).

options Specifies an array containing flags/options. Check each filter for possible flags and options.
Similar Functions
Popular Articles